/*
    BspI2C.h

    Implementation File for STM32 I2C Module
*/

/*
    Modification History
    --------------------
    01a 27Feb24 Jasper Created
*/


#ifndef __BSP_I2C_H__
#define __BSP_I2C_H__

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#include "ch32v20x.h"

#define     I2C_GPIO_PORT           GPIOB

#define     I2C_SCL_PIN             GPIO_Pin_14
#define     I2C_SDA_PIN             GPIO_Pin_13

#define     SDA_HIGH                GPIO_SetBits(I2C_GPIO_PORT, I2C_SDA_PIN)
#define     SDA_LOW                 GPIO_ResetBits(I2C_GPIO_PORT, I2C_SDA_PIN)

#define     SCL_HIGH                GPIO_SetBits(I2C_GPIO_PORT, I2C_SCL_PIN)
#define     SCL_LOW                 GPIO_ResetBits(I2C_GPIO_PORT, I2C_SCL_PIN)

#define     SDA_READ                GPIO_ReadInputDataBit(I2C_GPIO_PORT, I2C_SDA_PIN)

extern void I2C_Config(void);

extern uint8_t I2C_WriteByte(uint8_t SendByte, uint8_t WriteAddress, uint8_t DeviceAddress);
extern uint8_t I2C_ReadByteN(uint8_t ReadAddress,  uint8_t DeviceAddress);
extern uint8_t I2C_WriteBurst(uint8_t *SendData, uint8_t StartAddress, uint8_t DeviceAddress, uint8_t DataLength);

#endif /* __BSP_I2C_H__ */

